package com.party.course.controller;


import java.util.Arrays;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.IdUtil;
import com.party.common.annotation.Log;
import com.party.common.core.controller.BaseController;
import com.party.common.core.domain.AjaxResult;
import com.party.common.enums.BusinessType;
import com.party.common.utils.StringUtils;
import com.party.common.utils.poi.ExcelUtil;
import com.party.common.utils.spring.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.party.course.domain.PlanClass;
import com.party.course.service.IplanClassService;
import com.party.common.core.page.TableDataInfo;

/**
 * 排课信息Controller
 *
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/course/planClass")
public class PlanClassController extends BaseController {
    @Resource
    private IplanClassService planClassService;

    /**
     * 查询排课信息列表
     */
//@RequiresPermissions("course:planClass:list")
    @GetMapping("/list")
    public TableDataInfo list(PlanClass planClass) {
        List<PlanClass> list = planClassService.findList(planClass);
        return getDataTable(list);
    }


    @GetMapping("/listPlan")
    public TableDataInfo listPlan(PlanClass planClass) {
        List<PlanClass> list = planClassService.findList(planClass);
        return getDataTable(list);
    }

    /**
     * 导出排课信息列表
     */
    //@RequiresPermissions("course:planClass:export")
    @Log(title = "排课信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanClass planClass) {
        List<PlanClass> list = planClassService.findList(planClass);
        ExcelUtil<PlanClass> util = new ExcelUtil<PlanClass>(PlanClass.class);
        util.exportExcel(response, list, "排课信息数据");
    }

    /**
     * 获取排课信息详细信息
     */
    //@RequiresPermissions("course:planClass:query")
    @GetMapping(value = "/view/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(planClassService.view(id));
    }

    /**
     * 新增排课信息
     */
    //@RequiresPermissions("course:planClass:add")
    @Log(title = "排课信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PlanClass planClass) {
        return toAjax(planClassService.add(planClass));
    }

    /**
     * 消课
     *
     * @param id
     * @return
     */
    @GetMapping("/offClass")
    public AjaxResult offClass(String id, String tupe) {
        return toAjax(planClassService.offClass(id, tupe));
    }

    /**
     * 上课前2小时通知老师
     *
     * @param id
     * @return
     */
    @GetMapping("/classNotice")
    public AjaxResult classNotice(String id) {
        //定时任务 需要手动注入bean
        IplanClassService bean = SpringUtils.getBean(IplanClassService.class);
        bean.classNotice(id);
        return AjaxResult.success();
    }

    /**
     * 修改排课信息
     */
    //@RequiresPermissions("course:planClass:edit")
    @Log(title = "排课信息", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody PlanClass planClass) {
        return toAjax(planClassService.updateEntity(planClass));
    }


    @PutMapping("/updateFk")
    public AjaxResult updateFk(@RequestBody PlanClass planClass) {
        return toAjax(planClassService.updateEntityFk(planClass));
    }


    @PutMapping("/updateKjx")
    public AjaxResult updateKjx(@RequestBody PlanClass planClass) {
        return toAjax(planClassService.updateEntityKjx(planClass));
    }


    /**
     * 删除排课信息
     */
    //@RequiresPermissions("course:planClass:remove")
    @Log(title = "排课信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(planClassService.deleteIds(Arrays.asList(ids)));
    }
}
